package com.weipai.demo.service.impl;

import com.weipai.demo.enums.RetCode;
import com.weipai.demo.mapper.AdvertisingLocationMapper;
import com.weipai.demo.mapper.base.DAdvertisingLocationMapper;
import com.weipai.demo.model.AdvertisingLocation;
import com.weipai.demo.service.PicturnService;
import com.weipai.demo.util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 赵项阳
 * @Date: 2019/6/28 11:51
 * @Version 1.0
 */
@Service
public class PicturnServiceImpl implements PicturnService {

    @Autowired
    private AdvertisingLocationMapper advertisingLocationMapper;
    @Autowired
    private DAdvertisingLocationMapper dAdvertisingLocationMapper;



    //广告位的添加或修改
    @Override
    public Response locationSave(String advertisingLocation, Integer status, Integer id) {
        Response response=new Response();
        //判断id是否为空
        if (id!=null){
       advertisingLocationMapper.updateByid(advertisingLocation,status,id);
       response.setCode(RetCode.UPDATESUCCESS);
        }else {

            AdvertisingLocation advertisingLocation1=new AdvertisingLocation();
            advertisingLocation1.setAdvertisingLocation(advertisingLocation);
            advertisingLocation1.setStatus(status);

            int insert = dAdvertisingLocationMapper.insert(advertisingLocation1);
            response.setCode(RetCode.SUCCESS);
        }
        return response;
    }


    //广告位的删除
    @Override
    public Response deleByid(Integer id) {
        Response response=new Response();
        if (id!=null){
            int i = dAdvertisingLocationMapper.deleteByPrimaryKey(id);
            response.setCode(RetCode.SUCCESS);
        }else {
            response.setCode(RetCode.ID_NULL);
        }
        return response;
    }

    //展示广告位
    @Override
    public Response show() {
        Response response=new Response();
        List<AdvertisingLocation> selectAll = dAdvertisingLocationMapper.selectAll();
        response.put("selectAll",selectAll);
        response.setCode(RetCode.SUCCESS);
        return response;
    }

    //==================================================================================================================

}
